#ifndef VZCONN_POOL_PERFECT_BUFFER_POOL_H_
#define VZCONN_POOL_PERFECT_BUFFER_POOL_H_

#include "vzconn/base/basicdefines.h"
#include "vzconn/base/bytebuffer.h"
#include <list>
#include <vector>

namespace vzconn {

class PerfectBufferPool : public boost::noncopyable,
  public boost::enable_shared_from_this<PerfectBufferPool> {
 public:
  typedef boost::shared_ptr<PerfectBufferPool> Ptr;
  PerfectBufferPool();
  virtual ~PerfectBufferPool();
  static PerfectBufferPool *Instance();
  // Thread safed
  ByteBuffer::Ptr TakeBuffer(std::size_t mini_size);
  // Thread safed
  void RecyleBuffer(ByteBuffer::Ptr buffer);

 private:
  void InsertBuffer(ByteBuffer::Ptr buffer);
  ByteBuffer::Ptr TaskPerfectBuffer(std::size_t mini_size);
 private:
  typedef std::list<ByteBuffer::Ptr> Buffers;
  Buffers buffers_;
  boost::mutex pool_mutex_;
 private:
  static PerfectBufferPool *pool_instance_;
};
}

#endif // VZCONN_POOL_PERFECT_BUFFER_POOL_H_
